package com.jiuyuan.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @program: hrms
 * @description:
 * @author: Feng
 * @create: 2023-02-19 14:29
 **/

@Configuration
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        /**
         * @paths:将ws/ep注册为端点，用户连接即可通讯
         *@setAllowedOrigins：允许跨域
         * @withSockJS： 允许使用SockJS
         */
        registry.addEndpoint("ws/ep").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        //todo webSocket
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        /**
         * @Description:配置代理域，可以配置多个，通过代理域向客户端发送消息
         */
        registry.enableSimpleBroker("/queue");
    }
}
